package com.hooya.fa.eu.biz.business;

import com.hooya.fa.eu.biz.service.EuCheckService;
import com.hooya.fa.eu.biz.service.KcjlHyService;
import com.hooya.fa.eu.biz.service.StkCollectionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Slf4j
public class DealSourceData_01 {

	private final EuCheckService euCheckService;

	private final StkCollectionService stkCollectionService;

	private final KcjlHyService kcjlHyService;


	@GetMapping("/first")
	public void dealSourceData_01(String startDate, String endDate, int num) {

		try{
		log.info("1.dealSourceData_01开始执行");

//		pre_test();  //完成测试

//		eu_stk(startDate, endDate, num);  // 完成测试

//		kcjlHy(startDate, endDate);  // 完成测试

		post_test(endDate); // 完成测试

		log.info("1.dealSourceData_01执行完毕");

		}catch (Exception e){
			log.error("dealSourceData_01执行失败");
			throw new RuntimeException("dealSourceData_01执行失败", e);
		}

	}

	private void pre_test() {
		try {
			log.info("1.pre_test开始执行");
			euCheckService.checkAndInsertCkDict();
			log.info("1.pre_test执行成功");
		} catch (Exception e) {
			log.error("1.pre_test执行失败");
			throw new RuntimeException("1.pre_test执行失败", e);
		}
	}

	private void eu_stk(String startDate, String endDate, int num) {
		try {
			log.info("1.eu_stk开始执行");
			stkCollectionService.generatorCollectionData_daily(startDate, endDate, num);
			log.info("1.eu_stk执行成功");
		} catch (Exception e) {
			log.error("1.eu_stk执行失败");
			throw new RuntimeException("1.eu_stk执行失败", e);
		}
	}

	private void kcjlHy(String startDate, String endDate) {
		try {
			log.info("1.kcjlHy开始执行");
			kcjlHyService.KcjlHy(startDate, endDate);
			log.info("1.kcjlHy执行成功");
		} catch (Exception e) {
			log.error("1.kcjlHy执行失败");
			throw new RuntimeException("1.kcjlHy执行失败", e);
		}
	}

	private void post_test(String endDate) {
		try {
			log.info("1.post_test开始执行");
			System.out.println("我使用的自己的 - 正确");
			log.info("1.post_test执行成功");
		} catch (Exception e) {
			log.error("1.post_test执行失败");
			throw new RuntimeException("1.post_test执行失败", e);
		}
	}



}
